package guavaTest.order;

import com.google.common.collect.Ordering;

import java.util.ArrayList;
import java.util.List;

/**
 * 排序
 */
public class Main {
    public static void main(String[] args) {
        Main main = new Main();
//        main.orderInt();
        main.orderStudent();
    }

    public void orderInt(){
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            list.add((int) (Math.random()*100f));
        }
        Ordering<Integer> ordering = Ordering.natural();
        ordering.greatestOf(list,50);
//        ordering.greatestOf(list,11).forEach(item->{
//            System.out.println(item);
//        });
        System.out.println(ordering.greatestOf(list,50));
    }

    public void orderStudent(){
        List<Student> students = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            Student student = new Student((int) (Math.random()*100f),(int) (Math.random()*100f),String.valueOf(i));
            students.add(student);
        }

        Ordering<Student> ordering = Ordering.natural();
        System.out.println(ordering.sortedCopy(students));
        System.out.println(ordering.greatestOf(students,50));
    }

    public class Student implements Comparable<Student>{
        private int age;
        private int number;
        private String name;

        public Student(int age, int number, String name) {
            this.age = age;
            this.number = number;
            this.name = name;
        }

        @Override
        public int compareTo(Student student) {
            return (student.age > this.age)?0:1;
        }

        @Override
        public String toString() {
            return "Student{" +
                    "age=" + age +
                    ", number=" + number +
                    ", name='" + name + '\'' +
                    '}';
        }
    }
}
